<template>
  <div id="app">
    <Topbar :key="topbarKey" />
    <Header />
   
    <router-view @updateKey="updateKeyFn"/> 
    <!-- <span class="iconfont icon-toast-shibai_huaban"></span>
    <i class="iconfont icon-toast_chenggong"></i> -->
    <Footer />
    <!-- 多个组件需要控制当前这个组件的显示和隐藏 -->
      <Login v-show="isShowLoginModal" />
      <!-- 显示提示框 -->
      <transition name="slide">
      <Toast v-show="isShowToast"/>
      </transition>
      <!-- <button @click="fn">点击请求数据</button> -->
    <!-- <button @click="fn">点击请求数据{{isShowLoginModal}}</button> -->
  </div>
</template>
<script>
import Topbar from "./components/Topbar.vue"
import Header from "./components/Header.vue"
import Footer from "./components/Footer.vue"
import Login from "./components/Login.vue"
import Toast from "./components/Toast.vue"
// import axios from "axios";
// import request from "@/request/request.js"
import {JingPinAPI} from "@/request/api.js"
import {mapState} from "vuex"
export default {
  components:{
    Topbar,
    Header,
    Footer,
    Login,
    Toast
  },
  data(){
    return{
      topbarKey:0
    }
  },
  computed:{
    ...mapState({
      isShowLoginModal:(state)=>state.showModal.isShowLoginModal,
      isShowToast:(state)=>state.showToast.isShowToast
    })
  },
  created(){
     console.log("VUE_APP_MYNAME:",process.env.VUE_APP_MYNAME);
  //  JingPinAPI().then((res)=>{
  //     console.log("res:",res);
  //   }) 
    // request.get("/products/recommend").then((res)=>{
    //   console.log("res:",res);
    // })
    // axios.get("http://192.168.113.249:8081/cms/products/recommend").then((res)=>{
    //   console.log("res:",res);
    // })
  },
  methods:{
    // async fn(){
    //   let res1 = await JingPinAPI();
    //   console.log("res1:",res1); 
    //   // let res2 = await JingPinAPI();
    //   // console.log("res2:",res2); 
    //   // let res3 = await JingPinAPI();
    //   // console.log("res3:",res3);
    // },
    updateKeyFn(){
      this.topbarKey++;
    }
  },
  watch:{
     "$route.path":{
      handler(newVal,oldVal){
        console.log(newVal,oldVal);
        if(oldVal !="/"){
          this.topbarKey++;
        }
       
      }
    }
  }
}
</script>
<style lang="less">
.slide-enter,.slide-leave-to{
  opacity: 0;
}
.slide-enter-active,
.slide-leave-active{
  transition: opacity 0.5s linear;
}
.slide-enter-to,
.slide-leave{
  opacity: 1;
}
</style>
